//引入上边封装的axios文件
import request from "@/components/request";
// import QS from "qs";
import json from '@/json/json.json'
import config from '@/json/config.json'
import {segmentedEncryptionByPlaintext,strToBase64} from "@/utils/jesencrypt";

// const isUseJson = true;
const isUseJson = false;
//用户登录
export const userLogin = data => {
    console.log('userLogin',data)
    if (isUseJson) {
        const data = {
            "data": json.userLoginRest
        };
        // console.log(data)
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                //成功的时候调用resolve
                resolve(data)
                //失败的时候调用reject
                reject('error message')
            }, 1000)
        });
    } else {
        return request({
            url: "/user/login",
            method: "POST",
            headers: {
                "content-type": "application/json;charset=UTF-8"
            },
            data
        });
    }

};

//获取菜单消息
export const getMenuInfo = () => {

    const menuInfo = window.localStorage.getItem("menuInfo")

    return  JSON.parse(menuInfo);
    // console.log('getMenuInfo',data)
    // if (isUseJson) {
    //     const data = {
    //         "data": json.menuInfo
    //     };
    //     // console.log(data)
    //     return new Promise((resolve, reject) => {
    //         setTimeout(() => {
    //             //成功的时候调用resolve
    //             resolve(data)
    //             //失败的时候调用reject
    //             reject('error message')
    //         }, 1000)
    //     });
    // } else {
    //     return request({
    //         url: "/sys/getMenuInfo",
    //         method: "POST",
    //         headers: {
    //             "content-type": "application/json;charset=UTF-8"
    //         },
    //         data
    //     });
    // }

};
/**
 * post 请求
 * @param data 参数
 */
export const post = (url, data) => {
    return request({
        url: url,
        method: "POST",
        headers: {
            "content-type": "application/json;charset=UTF-8",
            // response.setHeader("Access-Control-Allow-Origin","*");
        },
        data
    });
};

//获取用户信息  post请求
export const getUserInfo = data => {
    return request({
        url: "/user/info",
        method: "POST",
        headers: {
            "content-type": "application/json;charset=UTF-8"
        },
        data
    });
};
//从session中获取用户信息
export const getSessionUserItem = () => {
    const userInfo = window.sessionStorage.getItem("userInfo")
    return userInfo;
}

//下载用户上传模板   get请求
export const downLoadTemplate = params => {
    return request({
        url: "/user/info/template",
        method: "GET",
        headers: {
            "content-type": "application/json;charset=UTF-8"
        },
        params
    });
};
//获取用户表格的表头信息
export const getTableHeadInfo = (tableName) => {
    const data = {
        'tableName': tableName
    };
    console.log('getTableHeadInfo',data)
    if (isUseJson) {
        const data = {
            "data": json.userListHead
        };
        // console.log(data)
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                //成功的时候调用resolve
                resolve(data)
                //失败的时候调用reject
                reject('error message')
            }, 1000)
        });
    } else {
        return request({
            url: "/sys/getMenuInfo",
            method: "POST",
            headers: {
                "content-type": "application/json;charset=UTF-8"
            },
            data
        });
    }
};
//获取用户表格的表头信息
export const getUserTableDataInfo = (data) => {
    console.log('getUserTableDataInfo',data)
    if (isUseJson) {
        const data = {
            "data": json.getUserTableDataInfo
        };
        // console.log(data)
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                //成功的时候调用resolve
                resolve(data)
                //失败的时候调用reject
                reject('error message')
            }, 1000)
        });
    } else {
        return request({
            url: "/sys/getUserTableDataInfo",
            method: "POST",
            headers: {
                "content-type": "application/json;charset=UTF-8"
            },
            data
        });
    }
};

let getConfig = function (data) {
    // console.log('getConfig')
    let jsonKey = data.jsonKey;
    console.log('getConfig',data)
    if (isUseJson) {
        const data = {};
        data.data = config[jsonKey];
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                //成功的时候调用resolve
                resolve(data)
                //失败的时候调用reject
                reject('error message')
            }, 1000)
        });
    } else {
        console.log('getConfig',jsonKey)
        return request({
            url: "/sys/getConfig",
            method: "POST",
            headers: {
                "content-type": "application/json;charset=UTF-8"
            },
            data
        });
    }
}
export default getConfig;








